package com.geekaca.news.service.impl;

import com.geekaca.news.domain.NewsTag;
import com.geekaca.news.mapper.NewsTagMapper;
import com.geekaca.news.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TagServiceImpl implements TagService {
    @Autowired
    private NewsTagMapper newsTagMapper;


    @Override
    public Integer getTotalTags() {
        return newsTagMapper.getTotalTags();
    }

    @Override
    public List<NewsTag> getAllTags(Integer page, Integer limit) {
        int start = (page - 1) * limit;
        int pageSize = limit;
        return newsTagMapper.getAllTags(start, pageSize);
    }

    @Override
    public int insertTag(String tagName) {
        NewsTag newsTag = new NewsTag();
        newsTag.setTagName(tagName);
        newsTag.setIsDeleted(0);
        newsTag.setCreateTime(new Date());
        return newsTagMapper.insert(newsTag);
    }

    @Override
    public int delTag(Long tagId) {
        return newsTagMapper.deleteByPrimaryKey(tagId);
    }

    @Override
    public NewsTag getTag(String tagName) {
        return newsTagMapper.selectByTagName(tagName);
    }
}
